package com.shiyu.exam.exception;


import com.shiyu.exam.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public Result handleException(Exception e) {
        log.error("发生了错误哦！ : {}", e.getMessage(), e);
        return Result.error("发生了错误哦！ : " + e.getMessage());
    }


    //处理EaxamException异常的方法
    @ExceptionHandler(value = ExamException.class)
    public Result doResolveException(ExamException e){
        log.error("业务异常：{}", e.getMessage());
        return Result.error(e.getCode(), e.getMessage());
    }
}
